/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package engine.goods;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mainpackage.Constant;
import mainpackage.GameBean;
import mainpackage.MainLogic;
import mainpackage.ResManager;
import mainpackage.Tools;

/**
 *
 * @author Administrator
 */
public class Goods {
    //物品的公共属性

    public short shMaxColumnNum = 0; //最大可以放置的物品的格子的数量
    public boolean[] bColumnHasGoods; // 当前格子中是否有物品
    public byte byColumnType; //物品栏的类型（物品栏类型：1：普通物品栏2：任务物品栏3：宠物物品栏
    public long[] lColumnKey;  //物品所在槽的key
    public short[] shGoodsType; //物品的类型（比如武器类，衣服类）
    public String[] sAlias; //物品中文名称,用于显示给玩家看
    public short shStackNum[]; //同一个格子中放置的数量
    public int[] iIconID; // 道具图片的ID号，不填写使用默认图片，通过ID获得物品图标
    public byte[] byPlace; // 如果物品可以装备，物品物品装备的位置
    public byte[] byColor; //物品的颜色
    public byte[] byJob; //物品使用的职业限制
    public byte[] byGender; // 物品使用的性别限制
    public byte[] byBind; //物品绑定情况
    public Image[] icon; //物品图片
    public String[] sGoodsDesc; //物品的简单描述
    public boolean[] bIsGetGoodsDesc; // 是否已经从服务器获得了物品的简单描述
    public byte[] byEquipMap; //装备的位置和ui索引的对应关系表
    public short[] shLevel; //物品的等级
    public int[] iPrice; //价格
    public byte[] byDurability; //耐久度
    public String[] sGoodsKey; //物品的key，区分物品的唯一标志
    public boolean[] bPlayerCanUse;
    public Image[] img;
//    public static byte bySelectState = 1;
    //#if NOKIA_S60V5
     public static byte byItemH = 41;
    //#else
//#    public static byte byItemH = 31;
    //#endif

    /***********************************************物品栏相关**********************************************/
    /**
     * 类实例化
     */
    public Goods(short shMaxColumnNum, byte byColumnType) {
        this.byColumnType = -1;
        this.shMaxColumnNum = -1;
        switch (byColumnType) {
            case Constant.ITEM_COLUMN_TYPE_EQUIP:
                this.initEquipment();
                break;
            default:
                this.init(shMaxColumnNum, byColumnType);
                break;
        }
    }

    /**
     * 初始化物品数组
     */
    public void init(short shMaxColumnNum, byte byColumnType) {
        if (this.byColumnType == -1) {//只初始化一遍
            //#if NOKIA_S60V5
             this.img = new Image[6];
            //#else
//#            this.img = new Image[5];
            //#endif
            try {
                this.img[0] = ResManager.createImage(90000028, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, -1);//物品背景
                this.img[1] = Tools.makeTransparent(28, 28, 220, 0xA42B21);//物品不可以使用情况下的背景
                this.img[2] = Tools.makeTransparent(ResManager.createImage(90000062), 255);//物品数字图片
                this.img[3] = ResManager.createImage(90000034, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, -1);//物品绑定图标
                this.img[4] = ResManager.createImage(90000093, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, -1);//物品绑定图标
                //#if NOKIA_S60V5
                 this.img[5] = ResManager.createImage(90000087, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, 220);
                //#endif
            } catch (Exception e) {
                if (Constant.DEBUG) {
                    e.printStackTrace();
                }
            }
        }
        this.shMaxColumnNum = shMaxColumnNum;
        if (this.shMaxColumnNum < 1) {
            return;
        }
        this.byColumnType = byColumnType;
        //初始化物品数组，赋给物品初始值
        this.bColumnHasGoods = new boolean[this.shMaxColumnNum];
        this.lColumnKey = new long[this.shMaxColumnNum];
        this.shGoodsType = new short[this.shMaxColumnNum];
        this.sAlias = new String[this.shMaxColumnNum];
        this.shStackNum = new short[this.shMaxColumnNum];
        this.iIconID = new int[this.shMaxColumnNum];
        this.byPlace = new byte[this.shMaxColumnNum];
        this.byColor = new byte[this.shMaxColumnNum];
        this.byJob = new byte[this.shMaxColumnNum];
        this.byGender = new byte[this.shMaxColumnNum];
        this.byBind = new byte[this.shMaxColumnNum];
        this.icon = new Image[this.shMaxColumnNum];
        this.sGoodsDesc = new String[this.shMaxColumnNum];
        this.bIsGetGoodsDesc = new boolean[this.shMaxColumnNum];
        this.shLevel = new short[this.shMaxColumnNum];
        this.iPrice = new int[this.shMaxColumnNum];
        this.byDurability = new byte[this.shMaxColumnNum];
        this.sGoodsKey = new String[this.shMaxColumnNum];
        this.bPlayerCanUse = new boolean[this.shMaxColumnNum];
        for (short i = 0; i < this.shMaxColumnNum; i++) {
            this.bIsGetGoodsDesc[i] = false;
            this.bPlayerCanUse[i] = true;
            this.addGoods((short) i, false, -1, (short) -1, null, (short) -1, -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, null, (short) -1, -1, (byte) -1, null);
        }


    }

    /**
     * 初始化装备
     */
    /**
     * 初始化装备数组
     */
    public void initEquipment() {
        if (this.byColumnType == -1) {//只初始化一遍
            //#if NOKIA_S60V5
             this.img = new Image[6];
            //#else
//#            this.img = new Image[5];
            //#endif
            try {
                this.img[0] = ResManager.createImage(90000028, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, -1);//物品背景
                this.img[1] = Tools.makeTransparent(28, 28, 80, 0xFF0000);//物品不耐久为0显示
                this.img[2] = Tools.makeTransparent(ResManager.createImage(90000062), 255);//物品数字图片
                this.img[3] = ResManager.createImage(90000034, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, -1);//物品绑定图标
                this.img[4] = ResManager.createImage(90000093, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, -1);
                //#if NOKIA_S60V5
                 this.img[5] = ResManager.createImage(90000087, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, 220);
                //#endif
            } catch (Exception e) {
                if (Constant.DEBUG) {
                    e.printStackTrace();
                }
            }
        }
        this.byColumnType = Constant.ITEM_COLUMN_TYPE_EQUIP;
        this.shMaxColumnNum = Constant.PLAYER_WEAR_EQUIP_NUM;
        //初始化物品数组，赋给物品初始值
        this.bColumnHasGoods = new boolean[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.sAlias = new String[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.iIconID = new int[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.byPlace = new byte[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.byColor = new byte[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.shLevel = new short[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.icon = new Image[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.byDurability = new byte[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.shStackNum = new short[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.byJob = new byte[Constant.PLAYER_WEAR_EQUIP_NUM];
        this.byBind = new byte[Constant.PLAYER_WEAR_EQUIP_NUM];
        for (short i = 0; i < Constant.PLAYER_WEAR_EQUIP_NUM; i++) {
            this.addEquipment(i, false, null, -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1);
        }
        this.initEquipMap();

    }

    /**
     *初始化Ui界面的装备索引和装备位置的对应关系
     */
    public void initEquipMap() {
        this.byEquipMap = new byte[Constant.PLAYER_WEAR_EQUIP_NUM + 1];
        this.byEquipMap[Constant.EQUIP_POS_WEAPON] = 0;
        this.byEquipMap[Constant.EQUIP_POS_HEAD] = 1;
        this.byEquipMap[Constant.EQUIP_POS_CHEST] = 2;
        this.byEquipMap[Constant.EQUIP_POS_LEGS] = 3;
        this.byEquipMap[Constant.EQUIP_POS_FOOT] = 4;
        this.byEquipMap[Constant.EQUIP_POS_NECK] = 5;
        this.byEquipMap[Constant.EQUIP_POS_AMULET] = 6;
        this.byEquipMap[Constant.EQUIP_POS_WRIST] = 7;
        this.byEquipMap[Constant.EQUIP_POS_FINGER] = 8;
        this.byEquipMap[Constant.EQUIP_POS_MOUNTS] = 9;
    }

    /**
     * 获得装备栏UI界面的装备位置的名称
     * @return
     */
    public static String[] getEquipPlaceName() {
        return new String[]{"武器", "帽子", "衣服", "裤子", "鞋子", "项链", "玉佩", "手镯", "戒指", "坐骑"};
    }

    /**
     * 通过装备位置获得索引位置
     * @return
     */
    public byte getEquipColumnIndex(byte byEquipPlace) {
        return this.byEquipMap[byEquipPlace];
    }

    /***
     * 设置物品所咋的栏
     */
    public void setColumnType(byte byColumnType) {
        this.byColumnType = byColumnType;
    }

    /**
     * 获得物品栏的类型
     */
    public byte getColumnType() {
        return this.byColumnType;
    }

    public short getGoodsLevel(short columnIndex) {
        return this.shLevel != null ? this.shLevel[columnIndex] : (short) 0;
    }

    /**
     * 添加物品
     * @param shColumnIndex 物品槽的索引，决定物品的位置
     * @param bColumnHasGoods  是否有物品
     * @param lColumnKey 物品槽的64唯一key
     * @param shGoodsType  物品的类型
     * @param sAlias   物品的名称
     * @param shStackNum 同一个槽中放置的物品的数量(堆叠数量)
     * @param iIconID  物品使用的图标ID
     * @param byPlace  如果物品可以装备，物品装备的位置
     * @param byColor  物品的名称颜色
     * @param byJob   使用职业
     * @param byGender 使用性别
     * @param byBind  绑定情况
     * @param sDesc    描述
     * @param shLevel  等级
     * @param iPrice  价格
     * @param byDurability 耐久度
     * @param sGoodsKey  物品的key
     */
    public void addGoods(short shColumnIndex, boolean bColumnHasGoods, long lColumnKey, short shGoodsType, String sAlias, short shStackNum, int iIconID, byte byPlace, byte byColor, byte byJob, byte byGender, byte byBind, String sDesc, short shLevel, int iPrice, byte byDurability, String sGoodsKey) {
        if (shColumnIndex < 0) {
            return;
        }
        //如果还是没有位置，直接返回
        this.bColumnHasGoods[shColumnIndex] = bColumnHasGoods;
        this.lColumnKey[shColumnIndex] = lColumnKey;
        this.shGoodsType[shColumnIndex] = shGoodsType;
        this.sAlias[shColumnIndex] = sAlias;
        this.shStackNum[shColumnIndex] = shStackNum;
        this.iIconID[shColumnIndex] = iIconID;
        this.byPlace[shColumnIndex] = byPlace;
        this.byColor[shColumnIndex] = byColor;
        this.byJob[shColumnIndex] = byJob;
        this.byGender[shColumnIndex] = byGender;
        this.byBind[shColumnIndex] = byBind;
        this.shLevel[shColumnIndex] = shLevel;
        this.iPrice[shColumnIndex] = iPrice;
        this.byDurability[shColumnIndex] = byDurability;
        this.sGoodsKey[shColumnIndex] = sGoodsKey;
        if (bColumnHasGoods) {
            if (sDesc != null && !sDesc.equals("")) {
                this.sGoodsDesc[shColumnIndex] = this.makeGoodsSimpleDesc(sAlias, byColor, shLevel, byJob, byGender) + sDesc;
                this.bIsGetGoodsDesc[shColumnIndex] = true;
            } else {
                this.sGoodsDesc[shColumnIndex] = this.makeGoodsSimpleDesc(sAlias, byColor, shLevel, byJob, byGender);
                this.bIsGetGoodsDesc[shColumnIndex] = false;
            }
            this.icon[shColumnIndex] = null;
            this.icon[shColumnIndex] = getGoodsIconFromID(iIconID);
            if (this.icon[shColumnIndex] == null) {
                this.icon[shColumnIndex] = ResManager.createImage(10001, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, true, -1);
            }
            this.setPlayerCanUseItem(shColumnIndex);
        } else {
            this.sGoodsDesc[shColumnIndex] = null;
            this.bIsGetGoodsDesc[shColumnIndex] = false;
            this.icon[shColumnIndex] = null;
            this.bPlayerCanUse[shColumnIndex] = true;
        }
    }

    /**
     * 判断判读当前物品任务是否可以使用
     */
    private void setPlayerCanUseItem(short shColumnIndex) {
        this.bPlayerCanUse[shColumnIndex] = this.bLevelSuitPlayer(shColumnIndex) && this.bJobSuitPlayer(shColumnIndex);
    }

    private boolean bLevelSuitPlayer(short shColumnIndex) {
//        return true;
        if (this.getGoodsCatalog(shColumnIndex) == Constant.ITEM_TYPE_PETS) {
            return MainLogic.getInstance().gamePlayer.iPlayerLevel + 4 >= this.shLevel[shColumnIndex] ? true : false;
        } else {
            return MainLogic.getInstance().gamePlayer.iPlayerLevel >= this.shLevel[shColumnIndex] ? true : false;
        }
    }

    private boolean bJobSuitPlayer(short shColumnIndex) {
//        return true;
        if (this.byJob != null && this.byJob[shColumnIndex] != 0) {
            //有职业限制
            return MainLogic.getInstance().gamePlayer.iplayerOccupation == this.byJob[shColumnIndex] ? true : false;
        } else {
            return true;
        }
    }

    /**
     * 穿上装备
     * @param shColumnIndex
     * @param bColumnHasGoods
     * @param sAlias
     * @param iIconID
     * @param byPlace
     * @param byQuality
     */
    public void addEquipment(short shColumnIndex, boolean bColumnHasGoods, String sAlias, int iIconID, byte byPlace, byte byColor, short shLevel, byte byDurability, byte byJob, byte byBind) {
        if (shColumnIndex < 0) {
            return;
        }
        //如果还是没有位置，直接返回
        this.bColumnHasGoods[shColumnIndex] = bColumnHasGoods;
        this.sAlias[shColumnIndex] = sAlias;
        this.iIconID[shColumnIndex] = iIconID;
        this.byPlace[shColumnIndex] = byPlace;
        this.byColor[shColumnIndex] = byColor;
        this.shLevel[shColumnIndex] = shLevel;
        this.byDurability[shColumnIndex] = byDurability;
        this.shStackNum[shColumnIndex] = 1;
        this.byJob[shColumnIndex] = byJob;
        this.byBind[shColumnIndex] = byBind;
        if (bColumnHasGoods) {
            this.icon[shColumnIndex] = getGoodsIconFromID(iIconID);
        }
    }

    /**
     * 是否已从网络获得了物品的描述
     */
    public boolean isGetGoodsDesc(short columnIndex) {
        return this.bIsGetGoodsDesc[columnIndex];
    }

    /**
     * 获得物品的描述
     * @param columnIndex
     * @return
     */
    public String getGoodsDesc(short columnIndex) {
        return this.sGoodsDesc[columnIndex];
    }

    /*
     *设置物品的描述
     */
    public void setGoodsDesc(short columnIndex, String desc, boolean bAddSimple) {
        if (bAddSimple) {
            this.sGoodsDesc[columnIndex] = this.makeGoodsSimpleDesc(this.sAlias[columnIndex], this.byColor[columnIndex], this.shLevel[columnIndex], this.byJob[columnIndex], this.byGender[columnIndex]) + desc;
        } else {
            this.sGoodsDesc[columnIndex] = desc;
        }
        this.bIsGetGoodsDesc[columnIndex] = true;
    }

    /**
     * 有多少物品
     * @return
     */
    public short getGoodsNum() {
        short num = 0;
        for (short i = 0; i < this.shMaxColumnNum; i++) {
            if (this.bColumnHasGoods[i]) {
                num++;
            }
        }
        return num;
    }

    /**
     * 返回可以放置物品的格子数量
     * @return
     */
    public short getMaxColumNum() {
        return this.shMaxColumnNum;
    }

    /**
     * 
     * @return
     * 检验格式索引总是否有物品
     */
    public boolean checkColumnHasGoods(short columnIndex) {
        return columnIndex >= 0 && columnIndex < this.shMaxColumnNum && this.bColumnHasGoods[columnIndex];
    }

    public byte checkColumn(short columnIndex) {
        if (columnIndex < 0 || columnIndex >= this.shMaxColumnNum) {
            return -1;//没有在物品数组范围内
        } else if (this.bColumnHasGoods[columnIndex]) {
            return 1;//有物品
        } else {
            return 0;//没有物品
        }
    }

    /**
     * 获得某个物品的中文名字
     * @param index
     * @return
     */
    public String getGoodsAlias(short columnIndex) {
        return this.sAlias[columnIndex];
    }

    /**
     * 获得某个物品的图标
     * @param iconID
     * @return
     */
    public Image getGoodsIcon(short columnIndex) {
        return this.icon[columnIndex];
    }

    /**
     * 获得物品图片的ID
     */
    public int getGoodsIconID(short columnIndex) {
        return this.iIconID[columnIndex];
    }

    /**
     * 获得某个物品的key
     * @param iconID
     * @return
     */
    public long getGoodsColumnKey(short columnIndex) {
        return this.lColumnKey[columnIndex];
    }

    /**
     * 获得某个物品在一个格子中堆叠的数量
     * @param iconID
     * @return
     */
    public short getGoodsStackNum(short columnIndex) {
        return this.shStackNum[columnIndex];
    }

    /**
     *
     * @param columnIndex
     * @param num
     * @return
     */
    public short setGoodsStackNum(short columnIndex, short num) {
        return this.shStackNum[columnIndex] = num;
    }
    /*
     * 获得物品的类型
     */

    public short getGoodsType(short columnIndex) {
        return this.shGoodsType[columnIndex];
    }

    /*
     * 获得物品的职业
     */
    public byte getGoodsJob(short columnIndex) {
        return this.byJob[columnIndex];
    }

    /*
     * 获得物品的使用性别限制
     */
    public byte getGoodsGender(short columnIndex) {
        return this.byGender[columnIndex];
    }

    /*
     * 获得物品的绑定情况
     */
    public byte getGoodsBind(short columnIndex) {
        return this.byBind[columnIndex];
    }

    /**
     * 物品的装备位置
     * @return
     */
    public byte getGoodsEquipPlace(short columnIndex) {
        return this.byPlace[columnIndex];
    }

    /**
     *
     * @物品的品质
     */
    public byte getGoodsColor(short columnIndex) {
        return this.byColor != null ? this.byColor[columnIndex] : (byte) -1;
    }

    /**
     * 获得物品的售价
     * @param columnIndex
     * @return
     */
    public int getGoodsPrice(short columnIndex) {
        return this.iPrice[columnIndex];
    }

    /**
     * 物品耐久度
     * @param columnIndex
     * @return
     */
    public byte getGoodsDurability(short columnIndex) {
        return this.byDurability[columnIndex];
    }

    /**
     * 物品key
     * @param columnIndex
     * @return
     */
    public String getGoodsKey(short columnIndex) {
        return this.sGoodsKey[columnIndex];
    }


    /*
     * 判断图片是否在本地,暂时的使用
     */
    public static boolean isIconIDPicInLocal(int iconID) {
        int iLocalIcon[] = new int[]{31173,  1173,1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1244, 1245, 1246, 1247, 1252, 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1299, 1308, 1309, 1310, 1311, 1312, 1313, 1314, 1315, 1316, 1338, 1339, 1352, 1353, 1354, 1361, 1362, 1363, 1364, 1365, 1366, 1367, 1368, 1369, 1370, 1371, 1372, 1373, 1374, 1375, 1376, 1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1468, 1469, 1470, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1513, 1514, 1515, 1516, 1517, 1518, 1519, 1547, 1563, 1564, 1565, 1566, 1567, 1568};
        for (int i = 0; i < iLocalIcon.length; i++) {
            if (iconID == iLocalIcon[i]) {
                return true;
            }
        }
        return false;
    }

    /**
     * 获得物品的侠士图片
     * @param iconID
     * @return 
     */
    public static Image getGoodsIconFromID(int iconID) {
        if (iconID < 0) {
            return null;
        }
        if (isIconIDPicInLocal(iconID)) {
            return ResManager.createImage(iconID);
        } else {
            return ResManager.createImage(10001, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, true, -1);
        }
    }

    /**
     *
     * @param 删除物品
     * @param index
     */
    public void deleteGoods(short columnIndex) {
        this.addGoods(columnIndex, false, -1, (short) -1, null, (short) -1, -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, null, (byte) -1, -1, (byte) -1, null);
    }

    public void drawGoodsStackNum(Graphics g, String sNum, Image numPic, int startX, int startY) {
        String numeric;
        for (byte i = 0; i < sNum.length(); i++) {
            numeric = sNum.substring(i, i + 1);
            g.drawRegion(numPic, 50 + Byte.parseByte(numeric) * 5, 0, 5, 7, Constant.TRANS_NONE, startX, startY, 0);
            startX = startX + 4;
        }
    }

    public int getGoodsStackNumWidth(String sNum) {
        return sNum.length() * 7;
    }

    /**
     * 生成物品的背景图片
     * @param byType
     * @return 
     */
    public static Image createGoodsBg(byte byType) {
        if (byType == 1) {
            return ResManager.createImage(90000028);
        } else {
            return Tools.makeTransparent(28, 28, 220, 0xA42B21);
        }
    }

    public void drawGoods(Graphics g, int startX, int startY, short columnIndex) {
        drawGoods(g, startX, startY, columnIndex, true, true);
    }

    public void drawGoods(Graphics g, int startX, int startY, short columnIndex, boolean showCanNotUse, boolean bShowStackNum) {
        //#if NOKIA_S60V5
         //边框
         g.drawRegion(this.img[5], 0, 0, 17, 17, Constant.TRANS_NONE, startX, startY, 0);
         g.drawRegion(this.img[5], 19, 0, 24, 24, Constant.TRANS_NONE, startX + 17, startY, 0);
         g.drawRegion(this.img[5], 0, 0, 17, 17, Constant.TRANS_ROT180, startX + 24, startY + 24, 0);
         g.drawRegion(this.img[5], 19, 0, 24, 24, Constant.TRANS_ROT180, startX, startY + 17, 0);
         startX += 6;
         startY += 6;
        //#endif
        if (columnIndex > -1 && columnIndex < this.shMaxColumnNum) {
            if (this.bColumnHasGoods[columnIndex]) {
                if (showCanNotUse) {
                    if (!this.bPlayerCanUse[columnIndex] && this.img[1] != null) {
                        //#if NOKIA_S60V5
                        //#else
//#                        Tools.setColor(g, 0x000000);
//#                        g.drawRect(startX, startY, 30, 30);
                        //#endif
                        g.drawImage(this.img[1], startX + 1, startY + 1, 0);
                    } else {
                        g.drawImage(this.img[0], startX, startY, 0);
                        g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR, startX + 15, startY, 0);
                        g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR_ROT180, startX, startY + 15, 0);
                        g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_ROT180, startX + 15, startY + 15, 0);
                    }
                } else {
                    g.drawImage(this.img[0], startX, startY, 0);
                    g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR, startX + 15, startY, 0);
                    g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR_ROT180, startX, startY + 15, 0);
                    g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_ROT180, startX + 15, startY + 15, 0);
                }
                //格子可以用已经放了东西;
                g.drawImage(this.icon[columnIndex], startX + ((30 - this.icon[columnIndex].getWidth()) >> 1), startY + ((30 - this.icon[columnIndex].getHeight()) >> 1), 0);
                //绘制物品的品质颜色
                Tools.setColor(g, this.getGoodsNameColor(this.byColor[columnIndex]));
                g.drawRect(startX + 1, startY + 1, 27, 27);
                //左上
                g.drawRect(startX + 1, startY + 1, 1, 2);
                g.drawRect(startX + 1, startY + 1, 2, 1);
                //左下
                g.drawRect(startX + 1, startY + 26, 1, 2);
                g.drawRect(startX + 1, startY + 27, 2, 1);
                //右上
                g.drawRect(startX + 26, startY + 1, 2, 1);
                g.drawRect(startX + 27, startY + 1, 1, 2);
                //右下
                g.drawRect(startX + 27, startY + 26, 1, 2);
                g.drawRect(startX + 26, startY + 27, 2, 1);
                //绘制物品的数量
                if (bShowStackNum && this.img[2] != null && this.shStackNum[columnIndex] > 0) {
                    this.drawGoodsStackNum(g, String.valueOf(this.shStackNum[columnIndex]), this.img[2], startX + 30 - this.getGoodsStackNumWidth(String.valueOf(this.shStackNum[columnIndex])), startY + 30 - 7);
                }
                if (this.byBind != null && this.byBind[columnIndex] == 1 && this.img[3] != null) {
                    g.drawImage(this.img[3], startX + 15, startY + 6, 0);
                }
            } else {
                g.drawImage(this.img[0], startX, startY, 0);
                g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR, startX + 15, startY, 0);
                g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR_ROT180, startX, startY + 15, 0);
                g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_ROT180, startX + 15, startY + 15, 0);
            }
        } else {
            //当前格子不可用
            g.drawImage(this.img[0], startX, startY, 0);
            g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR, startX + 15, startY, 0);
            g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR_ROT180, startX, startY + 15, 0);
            g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_ROT180, startX + 15, startY + 15, 0);
            g.setColor(0x000000);
            g.drawLine(startX, startY, startX + 29, startY + 29);
            g.drawLine(startX + 29, startY, startX, startY + 29);
        }
    }

    /**
     * 绘制装备栏中的装备
     */
    public void drawEquipment(Graphics g, int startX, int startY, short columnIndex) {
        //#if NOKIA_S60V5
         //边框
         g.drawRegion(this.img[5], 0, 0, 17, 17, Constant.TRANS_NONE, startX, startY, 0);
         g.drawRegion(this.img[5], 19, 0, 24, 24, Constant.TRANS_NONE, startX + 17, startY, 0);
         g.drawRegion(this.img[5], 0, 0, 17, 17, Constant.TRANS_ROT180, startX + 24, startY + 24, 0);
         g.drawRegion(this.img[5], 19, 0, 24, 24, Constant.TRANS_ROT180, startX, startY + 17, 0);
         startX += 6;
         startY += 6;
        //#endif
        g.drawImage(this.img[0], startX, startY, 0);
        g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR, startX + 15, startY, 0);
        g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR_ROT180, startX, startY + 15, 0);
        g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_ROT180, startX + 15, startY + 15, 0);
        if (columnIndex > -1 && columnIndex < this.shMaxColumnNum) {
            if (this.bColumnHasGoods[columnIndex]) {
                //格子可以用已经放了东西;
                g.drawImage(this.icon[columnIndex], startX + ((30 - this.icon[columnIndex].getWidth()) >> 1), startY + ((30 - this.icon[columnIndex].getHeight()) >> 1), 0);
                //绘制物品的品质颜色
                Tools.setColor(g, this.getGoodsNameColor(this.byColor[columnIndex]));
                g.drawRect(startX + 1, startY + 1, 27, 27);
                //左上
                g.drawRect(startX + 1, startY + 1, 1, 2);
                g.drawRect(startX + 1, startY + 1, 2, 1);
                //左下
                g.drawRect(startX + 1, startY + 26, 1, 2);
                g.drawRect(startX + 1, startY + 27, 2, 1);
                //右上
                g.drawRect(startX + 26, startY + 1, 2, 1);
                g.drawRect(startX + 27, startY + 1, 1, 2);
                //右下
                g.drawRect(startX + 27, startY + 26, 1, 2);
                g.drawRect(startX + 26, startY + 27, 2, 1);
                //绘制物品的数量
                if (this.img[2] != null && this.shStackNum != null && this.shStackNum[columnIndex] > 0) {
                    this.drawGoodsStackNum(g, String.valueOf(this.shStackNum[columnIndex]), this.img[2], startX + 30 - getGoodsStackNumWidth(String.valueOf(this.shStackNum[columnIndex])), startY + 30 - 7);
                }
                if (this.byBind != null && this.byBind[columnIndex] == 1 && this.img[3] != null) {
                    g.drawImage(this.img[3], startX + 15, startY + 6, 0);
                }
                if (this.byDurability[columnIndex] == 0 && this.img[1] != null) {
                    g.drawImage(this.img[1], startX + 1, startY + 1, 0);
                }
            }
        } else {
            //表示当前格子不可用
            Tools.setColor(g, 0x000000);
            g.drawLine(startX, startY, startX + 29, startY + 29);
            g.drawLine(startX + 29, startY, startX, startY + 29);
        }
    }

    /**
     *  绘制物品被选中的状态
     * 选中的样式,单独写，防止出现遮挡问题()
     * @param g
     * @param selectedPic  //选中的样式图片
     * @param startX   物品开始位置
     * @param startY
     */
//    public static void drawSelectStyle(Graphics g, Image selectedPic, int startX, int startY) {
//        //#if NOKIA_S60V5
////#         Tools.drawTilePic(g, (byte) 1, startX, startY - selectedPic.getHeight(), 40, selectedPic, 0, 0, selectedPic.getWidth(), selectedPic.getHeight(), Constant.TRANS_NONE);
////#         Tools.drawTilePic(g, (byte) 2, startX + 40, startY, 40, selectedPic, 0, 0, selectedPic.getWidth(), selectedPic.getHeight(), Constant.TRANS_ROT90);
////#         Tools.drawTilePic(g, (byte) 1, startX, startY + 40, 40, selectedPic, 0, 0, selectedPic.getWidth(), selectedPic.getHeight(), Constant.TRANS_ROT180);
////#         Tools.drawTilePic(g, (byte) 2, startX - selectedPic.getHeight(), startY, 40, selectedPic, 0, 0, selectedPic.getWidth(), selectedPic.getHeight(), Constant.TRANS_ROT270);
//        //#else
//        Tools.drawTilePic(g, (byte) 1, startX, startY - selectedPic.getHeight(), 30, selectedPic, 0, 0, selectedPic.getWidth(), selectedPic.getHeight(), Constant.TRANS_NONE);
//        Tools.drawTilePic(g, (byte) 2, startX + 30, startY, 30, selectedPic, 0, 0, selectedPic.getWidth(), selectedPic.getHeight(), Constant.TRANS_ROT90);
//        Tools.drawTilePic(g, (byte) 1, startX, startY + 30, 30, selectedPic, 0, 0, selectedPic.getWidth(), selectedPic.getHeight(), Constant.TRANS_ROT180);
//        Tools.drawTilePic(g, (byte) 2, startX - selectedPic.getHeight(), startY, 30, selectedPic, 0, 0, selectedPic.getWidth(), selectedPic.getHeight(), Constant.TRANS_ROT270);
//        //#endif
//    }
    public void drawSelectStyle(Graphics g, int startX, int startY) {
//        if (bySelectState < 1 || bySelectState > 3) {
//            bySelectState = 1;
//        }
        //#if NOKIA_S60V5
 //        g.drawRegion(this.img[4], (bySelectState - 1) * 14, 0, 14, 14, Constant.TRANS_NONE, startX, startY, 0);
 //        g.drawRegion(this.img[4], (bySelectState - 1) * 14, 0, 14, 14, Constant.TRANS_ROT90, startX + 27, startY, 0);
 //        g.drawRegion(this.img[4], (bySelectState - 1) * 14, 0, 14, 14, Constant.TRANS_ROT180, startX + 27, startY + 27, 0);
 //        g.drawRegion(this.img[4], (bySelectState - 1) * 14, 0, 14, 14, Constant.TRANS_ROT270, startX, startY + 27, 0);
         g.drawImage(this.img[4], startX, startY, 0);
         g.drawRegion(this.img[4], 0, 0, 12, 12, Constant.TRANS_ROT90, startX + 29, startY, 0);
         g.drawRegion(this.img[4], 0, 0, 12, 12, Constant.TRANS_ROT180, startX + 29, startY + 29, 0);
         g.drawRegion(this.img[4], 0, 0, 12, 12, Constant.TRANS_ROT270, startX, startY + 29, 0);
        //#else
//#//        g.drawRegion(this.img[4], (bySelectState - 1) * 14, 0, 14, 14, Constant.TRANS_NONE, startX, startY, 0);
//#//        g.drawRegion(this.img[4], (bySelectState - 1) * 14, 0, 14, 14, Constant.TRANS_ROT90, startX + 17, startY, 0);
//#//        g.drawRegion(this.img[4], (bySelectState - 1) * 14, 0, 14, 14, Constant.TRANS_ROT180, startX + 17, startY + 17, 0);
//#//        g.drawRegion(this.img[4], (bySelectState - 1) * 14, 0, 14, 14, Constant.TRANS_ROT270, startX, startY + 17, 0);
//#        g.drawImage(this.img[4], startX, startY, 0);
//#        g.drawRegion(this.img[4], 0, 0, 12, 12, Constant.TRANS_ROT90, startX + 19, startY, 0);
//#        g.drawRegion(this.img[4], 0, 0, 12, 12, Constant.TRANS_ROT180, startX + 19, startY + 19, 0);
//#        g.drawRegion(this.img[4], 0, 0, 12, 12, Constant.TRANS_ROT270, startX, startY + 19, 0);
        //#endif
//        if (bySelectState >= 3) {
//            bySelectState = 1;
//        } else {
//            bySelectState++;
//        }
    }

    public static void drawGoodsSelectStytle(Graphics g, Image selectPic, int startX, int startY) {
        //#if NOKIA_S60V5
         g.drawImage(selectPic, startX, startY, 0);
         g.drawRegion(selectPic, 0, 0, 12, 12, Constant.TRANS_ROT90, startX + 29, startY, 0);
         g.drawRegion(selectPic, 0, 0, 12, 12, Constant.TRANS_ROT180, startX + 29, startY + 29, 0);
         g.drawRegion(selectPic, 0, 0, 12, 12, Constant.TRANS_ROT270, startX, startY + 29, 0);
        //#else
//#        g.drawImage(selectPic, startX, startY, 0);
//#        g.drawRegion(selectPic, 0, 0, 12, 12, Constant.TRANS_ROT90, startX + 19, startY, 0);
//#        g.drawRegion(selectPic, 0, 0, 12, 12, Constant.TRANS_ROT180, startX + 19, startY + 19, 0);
//#        g.drawRegion(selectPic, 0, 0, 12, 12, Constant.TRANS_ROT270, startX, startY + 19, 0);
        //#endif

    }

    /**
     * 删除/卸载人身上的装备
     * @param place
     */
    public void deleteEquipment(byte byEquipPlace) {
        this.addEquipment(this.getEquipColumnIndex(byEquipPlace), false, null, -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1);
        MainLogic.getInstance().gamePlayer.deleteAvatorAni(byEquipPlace);
    }

    /**
     *绘制弹出的物品操作层
     *startY:格子开始的位置
     */
    public static void drawGoodsOperationMenu(Graphics g, String[] sOpArray, byte bySelectIndex, int startX, int startY) {
        int width = 0;
        for (byte i = 0; i < sOpArray.length; i++) {
            width = width > sOpArray[i].length() ? width : sOpArray[i].length();
        }
        width = width * Constant.FONT_CHAR_WIDTH;
        //#if NOKIA_S60V5
         width = width > 41 ? width + 2 : 43;
        //#else
//#        width = width > 31 ? width + 2 : 33;
        //#endif
        Tools.drawPopMenu(g, sOpArray, (byte) 1, width, Constant.FONT_SMALL_HEIGHT, 0x000000, 0xFFFFFF, 0x00CCFF, bySelectIndex, startX - 1, startY);
    }

    public String[] getGoodsOpArray(short columnIndex) {
        if (columnIndex >= this.shMaxColumnNum) {
            return null;
        }
        if (this.getGoodsCatalog(columnIndex) == Constant.ITEM_TYPE_PETS) {
            return this.getPetOperation(this.byColumnType, this.byBind[columnIndex]);
        } else {
            return getGoodsOperation(this.byColumnType, getGoodsOperationType(this.shGoodsType[columnIndex]));

        }
    }

    /**
     * 获得宠物的操作方法
     * @param pos  //位置
     * @param byState  //类型
     * @return 
     */
    public static String[] getPetOperation(byte pos, byte byState) {
        switch (pos) {
            case Constant.ITEM_COLUMN_TYPE_PET_EQUIP:
                if (byState == 1) {
                    return new String[]{"改名", "休息", "喂养", "道具", "卸下"};
                } else {
                    return new String[]{"改名", "守护", "喂养", "道具", "卸下"};
                }
            case Constant.ITEM_COLUMN_TYPE_PET:
                if (byState == 1) {
                    return new String[]{"装备", "查看", "解绑", "放生", "移动"};
                } else {
                    return new String[]{"装备", "查看", "绑定", "放生", "移动"};
                }
        }
        return null;
    }

    /**
     * @param pos 物品在那个栏中(装备栏/物品栏/道具栏/宠物栏/快捷栏)
     * @param byItemType //物品的种类
     * @return
     */
    public static String[] getGoodsOperation(byte pos, byte byItemType) {
        switch (pos) {
            case Constant.ITEM_COLUMN_TYPE_COMMON:
                //包裹普通栏
                switch (byItemType) {
                    case Constant.ITEM_TYPE_CONSUMABLES:
                        return new String[]{"查看", "使用", "丢弃", "移动"};
                    case Constant.ITEM_TYPE_WEAPONS:
                    case Constant.ITEM_TYPE_EQUIP:
                        return new String[]{"装备", "查看", "对比", "丢弃", "移动"};
                    case Constant.ITEM_TYPE_GEM:
                        return new String[]{"查看", "丢弃", "移动"};
                    case Constant.ITEM_TYPE_SKILLS_BOOKS:
                    case Constant.ITEM_TYPE_FORMULA:
                        return new String[]{"查看", "学习", "丢弃", "移动"};
                    case Constant.ITEM_TYPE_PROPS:
                        return new String[]{"查看", "丢弃", "移动"};
                    case Constant.ITEM_TYPE_USE_PROPS:
                        return new String[]{"查看", "使用", "丢弃", "移动"};
                    case Constant.ITEM_TYPE_PET_FOOD:
                        return new String[]{"查看", "丢弃", "移动"};
                    case Constant.ITEM_TYPE_OTHERS:
                        return new String[]{"查看", "丢弃", "移动"};
                }
                break;
            case Constant.ITEM_COLUMN_TYPE_EQUIP_PACKAGE:
                switch (byItemType) {
                    case Constant.ITEM_TYPE_WEAPONS:
                    case Constant.ITEM_TYPE_EQUIP:
                        return new String[]{"装备", "查看", "对比", "丢弃"};
                }
                //装备栏包裹界面
                break;
            case Constant.ITEM_COLUMN_TYPE_TASK:
                //任务物品栏
                switch (byItemType) {
                    case Constant.ITEM_TYPE_TASK_PROPS:
                        return new String[]{"查看", "移动"};
                    case Constant.ITEM_TYPE_USE_TASK_PROPS:
                        return new String[]{"查看", "使用", "移动"};
                }
                break;
            case Constant.ITEM_COLUMN_TYPE_EQUIP:
                //装备栏
                switch (byItemType) {
                    case Constant.ITEM_TYPE_WEAPONS:
                    case Constant.ITEM_TYPE_EQUIP:
                        return new String[]{"查看", "卸下"};
                }
                break;
            case Constant.ITEM_COLUMN_TYPE_OTHERPLAYER_EQUIP:
                switch (byItemType) {
                    case Constant.ITEM_TYPE_WEAPONS:
                    case Constant.ITEM_TYPE_EQUIP:
                        return new String[]{"查看"};
                }
                break;
        }
        return null;
    }

    /**
     * 获得装备物品的类型
     * @param equipPos 物品装备的位置
     * @return
     */
    public static byte getEquipmentType(byte equipPos) {
        byte byItemType = -1;
        switch (equipPos) {
            case Constant.EQUIP_POS_HEAD:
            case Constant.EQUIP_POS_NECK:
            case Constant.EQUIP_POS_CHEST:
            case Constant.EQUIP_POS_LEGS:
            case Constant.EQUIP_POS_WRIST:
            case Constant.EQUIP_POS_FINGER:
            case Constant.EQUIP_POS_FOOT:
            case Constant.EQUIP_POS_AMULET:
            case Constant.EQUIP_POS_MOUNTS:
                byItemType = Constant.ITEM_TYPE_EQUIP;
                break;
            case Constant.EQUIP_POS_WEAPON:
                byItemType = Constant.ITEM_TYPE_WEAPONS;
                break;
        }
        return byItemType;
    }

    /**
     * 根据物品的具体型号获得物品的类型
     * @param type 物品的具体型号
     * @return
     */
    public static byte getGoodsOperationType(short type) {
        if (type >= 150 && type <= 160) {
            return Constant.ITEM_TYPE_CONSUMABLES;
        } else if (type >= 200 && type <= 249) {
            return Constant.ITEM_TYPE_WEAPONS;
        } else if (type >= 250 && type <= 299) {
            return Constant.ITEM_TYPE_EQUIP;
        } else if (type >= 300 && type <= 399) {
            return Constant.ITEM_TYPE_GEM;
        } else if (type >= 400 && type <= 499) {
            return Constant.ITEM_TYPE_PETS;
        } else if (type >= 500 && type <= 520) {
            return Constant.ITEM_TYPE_SKILLS_BOOKS;
        } else if (type >= 521 && type <= 549) {
            return Constant.ITEM_TYPE_FORMULA;
        } else if (type >= 700 && type <= 719) {
            return Constant.ITEM_TYPE_PROPS;
        } else if (type >= 700 && type <= 719) {
            return Constant.ITEM_TYPE_PROPS;
        } else if (type == 750 || type == 755 || type == 760) {
            return Constant.ITEM_TYPE_PET_FOOD;
        } else if (type >= 720 && type <= 739) {
            return Constant.ITEM_TYPE_USE_PROPS;
        } else if (type >= 800 && type <= 819) {
            return Constant.ITEM_TYPE_TASK_PROPS;
        } else if (type >= 820 && type <= 839) {
            return Constant.ITEM_TYPE_USE_TASK_PROPS;
        } else {
            return Constant.ITEM_TYPE_OTHERS;
        }
    }

    public byte getGoodsCatalog(short shColumnIndex) {
        if (shColumnIndex >= this.shMaxColumnNum) {
            return -1;
        }
        return getGoodsOperationType(shGoodsType[shColumnIndex]);
    }

    /**
     * 根据操作字符串获得操作类型
     */
    public byte getOperationType(String[] opArray, byte selectIndex) {
        String op = opArray[selectIndex];
        byte operation = -1;
        if (op.equals("查看")) {
            switch (this.byColumnType) {
                case Constant.ITEM_COLUMN_TYPE_PET:
                    return Constant.ITEM_OPERATION_TYPE_CHECK_PET;
                case Constant.ITEM_COLUMN_TYPE_COMMON:
                case Constant.ITEM_COLUMN_TYPE_EQUIP_PACKAGE:
                case Constant.ITEM_COLUMN_TYPE_TASK:
                    return Constant.ITEM_OPERATION_TYPE_CHECK;
                case Constant.ITEM_COLUMN_TYPE_EQUIP:
                    return Constant.ITEM_OPERATION_TYPE_CHECK_EQUIP;
            }
        } else if (op.equals("使用")) {
            return Constant.ITEM_OPERATION_TYPE_USE;
        } else if (op.equals("对比")) {
            return Constant.ITEM_OPERATION_TYPE_DIFF;
        } else if (op.equals("移动")) {
            return Constant.ITEM_OPERATION_TYPE_MOVE;
        } else if (op.equals("装备")) {
            switch (this.byColumnType) {
                case Constant.ITEM_COLUMN_TYPE_PET:
                    return Constant.ITEM_OPERATION_TYPE_PET_USE;
                case Constant.ITEM_COLUMN_TYPE_COMMON:
                case Constant.ITEM_COLUMN_TYPE_EQUIP_PACKAGE:
                    return Constant.ITEM_OPERATION_TYPE_EQUIP;
            }
        } else if (op.equals("学习")) {
            return Constant.ITEM_OPERATION_TYPE_LEARNING;
        } else if (op.equals("丢弃")) {
            return Constant.ITEM_OPERATION_TYPE_DELETE;
        } else if (op.equals("合成")) {
            return Constant.ITEM_OPERATION_TYPE_COMBINING;
        } else if (op.equals("喂养")) {
            return Constant.ITEM_OPERATION_TYPE_FEED;
        } else if (op.equals("卸下")) {
            switch (this.byColumnType) {
                case Constant.ITEM_COLUMN_TYPE_EQUIP:
                    return Constant.ITEM_OPERATION_TYPE_DELETE_EQUIP;
            }
        } else if (op.equals("强化")) {
            return Constant.ITEM_OPERATION_TYPE_STRENGTH;
        } else if (op.equals("守护") || op.equals("休息")) {
            return Constant.ITEM_OPERATION_TYPE_PET_DEFEND;
        } else if (op.equals("购买")) {
            return Constant.ITEM_OPERATION_TYPE_BUY;
        } else if (op.equals("出售")) {
            return Constant.ITEM_OPERATION_TYPE_SOLD;
        } else if (op.equals("改名")) {
            return Constant.ITEM_OPERATION_TYPE_PET_CHANGE_ALIAS;
        } else if (op.equals("放生")) {
            return Constant.ITEM_OPERATION_TYPE_DELETE;
        } else if (op.equals("绑定") || op.equals("解绑")) {
            return Constant.ITEM_OPERATION_TYPE_PET_BIND;
        }
        return -1;
    }

    /**
     *向服务器发送的物品操作请求
     * @param columnIndex : 物品索引位置
     * @param columnType  ：物品所在物品栏的类型
     * @param opArray ： 物品操作动作数组
     * @param selectIndex： 当前操作索引
     * @return： 操作的类型
     */
    public byte sendGoodsOperationMSG(short columnIndex, String[] opArray, byte selectIndex) {
        byte opType = this.getOperationType(opArray, selectIndex);
        if (opType == (byte) -1) {
            return -1;
        }
        return sendGoodsOperationMSG(columnIndex, opType);
    }

    /**
     *向服务器发送的物品操作请求
     * @param columnIndex : 物品索引位置
     * @param columnType  ：物品所在物品栏的类型
     * @param opType ： 操作类型
     * @return： 操作的类型
     */
    public byte sendGoodsOperationMSG(short columnIndex, byte opType) {
        switch (opType) {
            case Constant.ITEM_OPERATION_TYPE_CHECK:// 查看
                MainLogic.getInstance().uiInterFace.sysMessage.checkItem(this.sAlias[columnIndex], this.byColor != null ? this.byColor[columnIndex] : -1, this.icon[columnIndex], MainLogic.getInstance().gamePlayer.lPlayerID, this.lColumnKey[columnIndex]);
                break;
            case Constant.ITEM_OPERATION_TYPE_CHECK_EQUIP:
                MainLogic.getInstance().uiInterFace.sysMessage.checkItem(this.sAlias[columnIndex], this.byColor != null ? this.byColor[columnIndex] : -1, this.icon[columnIndex], MainLogic.getInstance().gamePlayer.lPlayerID, this.byPlace[columnIndex]);
                break;
            case Constant.ITEM_OPERATION_TYPE_USE://使用
                GameBean.L_CMD_GOODS_SLOTKEY = this.lColumnKey[columnIndex];
                GameBean.BY_CMD_COLUMN_TYPE = this.byColumnType;
                if (this.shGoodsType[this.byColumnType] == 150) {
                    GameBean.SH_GOODS_TYPE = Constant.ITEM_TYPE_MEDICINE;
                } else {
                    GameBean.SH_GOODS_TYPE = this.getGoodsCatalog(columnIndex);
                }
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_USE_ITEM, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_DIFF://对比
                GameBean.L_CMD_GOODS_SLOTKEY = this.lColumnKey[columnIndex];
                MainLogic.getInstance().uiInterFace.sysMessage.checkDiffItem(this.sAlias[columnIndex], this.byColor[columnIndex], this.icon[columnIndex]);
                MainLogic.getInstance().send(Constant.MSG_NET_DIFF_EQUIP, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_EQUIP://装备MSG_NET_DIFF_EQUIP
                GameBean.L_CMD_GOODS_SLOTKEY = this.lColumnKey[columnIndex];
                if (MainLogic.getInstance().byGameState == Constant.GAME_UI_EQUIPMENT) {
                    GameBean.I_CMD_COLUMN_INDEX = columnIndex;
                } else {
                    GameBean.I_CMD_COLUMN_INDEX = 0;
                }
                MainLogic.getInstance().uiInterFace.sysMessage.checkUNLoadEquip(this.sAlias[columnIndex], this.byColor[columnIndex], this.icon[columnIndex], (byte) 1);
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_USE_EQUIP, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_LEARNING://学习
                GameBean.L_CMD_GOODS_SLOTKEY = this.lColumnKey[columnIndex];
                GameBean.BY_CMD_COLUMN_TYPE = this.byColumnType;
                Constant.ITEM_OPERATION_TYPE_RECORD = Constant.ITEM_OPERATION_TYPE_LEARNING;
                GameBean.SH_GOODS_TYPE = this.getGoodsCatalog(columnIndex);
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_USE_ITEM, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_DELETE://丢弃
                GameBean.L_CMD_GOODS_SLOTKEY = this.lColumnKey[columnIndex];
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_DELETE_ITEM, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_COMBINING://合成
                break;
            case Constant.ITEM_OPERATION_TYPE_FEED://喂养
                //先要打开背包
                GameBean.L_CMD_PET_SLOTKEY = this.lColumnKey[columnIndex];
                MainLogic.getInstance().uiPackage.showBag(Constant.ITEM_COLUMN_TYPE_COMMON);
                break;
            case Constant.ITEM_OPERATION_TYPE_DELETE_EQUIP://卸下装备
                GameBean.BY_CMD_EQUIP_PLACE = this.byPlace[columnIndex];
                MainLogic.getInstance().uiInterFace.sysMessage.checkUNLoadEquip(this.sAlias[columnIndex], this.byColor[columnIndex], this.icon[columnIndex], (byte) 2);
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_DELETE_EQUIP, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_CHECK_DESC://查看物品的描述
                GameBean.L_CMD_DESC_GOODS_KEY = this.lColumnKey[columnIndex];
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_CHECK_DESC, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_PET_DEFEND:
                GameBean.L_CMD_PET_SLOTKEY = this.lColumnKey[columnIndex];
                Tools.printLog("发送守护" + GameBean.L_CMD_PET_SLOTKEY + GameBean.BY_OP_TYPE);
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_PET_DEFEND, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_PET_USE:
                GameBean.L_CMD_GOODS_SLOTKEY = this.lColumnKey[columnIndex];
                GameBean.I_CMD_COLUMN_INDEX = columnIndex;
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_USE_PET, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_DELETE_PET:
                //卸载宠物
                GameBean.L_CMD_PET_SLOTKEY = this.lColumnKey[columnIndex];
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_DELETE_PET, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_CHECK_PET:
                MainLogic.getInstance().uiInterFace.sysMessage.checkPet(MainLogic.getInstance().gamePlayer.lPlayerID, this.lColumnKey[columnIndex]);
                break;
            case Constant.ITEM_OPERATION_TYPE_BUY:
                GameBean.BY_TYPE = 1;
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_FUNC_STORE, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_SOLD:
                GameBean.BY_TYPE = 2;
                GameBean.L_CMD_GOODS_SLOTKEY = this.lColumnKey[columnIndex];
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_FUNC_STORE, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_PET_BIND:
                GameBean.L_CMD_PET_SLOTKEY = this.getGoodsColumnKey(columnIndex);
                if (this.getGoodsBind(columnIndex) == 1) {
                    GameBean.BY_TYPE = 2;
                } else {
                    GameBean.BY_TYPE = 1;
                }
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_PET_BIND, Constant.SOCKET_MSG_TYPE_LOGIC);
                break;
            case Constant.ITEM_OPERATION_TYPE_PET_CHANGE_ALIAS:
                break;
        }
        return opType;
    }

    /**
     *
     * @param shColumnIndex  复制到的索引
     * @param copyFormItem   //复制的对象
     * @param shCopyIndex  //复制的目标索引
     */
    public void goodsClone(short shColumnIndex, Goods copyFormItem, short shCopyIndex) {
        //初始化物品数组，赋给物品初始值
        this.bColumnHasGoods[shColumnIndex] = copyFormItem.bColumnHasGoods[shCopyIndex];
        this.sAlias[shColumnIndex] = copyFormItem.sAlias[shCopyIndex];
        this.iIconID[shColumnIndex] = copyFormItem.iIconID[shCopyIndex];
        this.byPlace[shColumnIndex] = copyFormItem.byPlace[shCopyIndex];
        this.byColor[shColumnIndex] = copyFormItem.byColor[shCopyIndex];
        this.shLevel[shColumnIndex] = copyFormItem.shLevel[shCopyIndex];
        this.icon[shColumnIndex] = copyFormItem.icon[shCopyIndex];
        this.byDurability[shColumnIndex] = copyFormItem.byDurability[shCopyIndex];
        this.shStackNum[shColumnIndex] = copyFormItem.shStackNum[shCopyIndex];
        this.byJob[shColumnIndex] = copyFormItem.byJob[shCopyIndex];
        this.byBind[shColumnIndex] = copyFormItem.byBind[shCopyIndex];
        if (copyFormItem.byColumnType == Constant.ITEM_COLUMN_TYPE_EQUIP) {
            return;
        }
        this.lColumnKey[shColumnIndex] = copyFormItem.lColumnKey[shCopyIndex];
        this.shGoodsType[shColumnIndex] = copyFormItem.shGoodsType[shCopyIndex];
        this.byGender[shColumnIndex] = copyFormItem.byGender[shCopyIndex];
        this.iPrice[shColumnIndex] = copyFormItem.iPrice[shCopyIndex];
        this.sGoodsKey[shColumnIndex] = copyFormItem.sGoodsKey[shCopyIndex];
        this.sGoodsDesc[shColumnIndex] = copyFormItem.sGoodsDesc[shCopyIndex];
        this.bIsGetGoodsDesc[shColumnIndex] = copyFormItem.bIsGetGoodsDesc[shCopyIndex];
        this.bPlayerCanUse[shColumnIndex] = copyFormItem.bPlayerCanUse[shCopyIndex];
    }

    /**
     * 物品移动
     */
    public void moveGoods(short shMoveIndex, short shMoveDestIndex, short num, long key) {
        if (num > this.shStackNum[shMoveIndex]) {
            return;
        } else if (num == this.shStackNum[shMoveIndex]) {
            if (this.checkColumnHasGoods(shMoveDestIndex)) {
                this.shStackNum[shMoveDestIndex] = (short) (this.shStackNum[shMoveDestIndex] + num);
            } else {
                this.addGoods(shMoveDestIndex, true, this.lColumnKey[shMoveIndex], this.shGoodsType[shMoveIndex], this.sAlias[shMoveIndex], this.shStackNum[shMoveIndex], -1, this.byPlace[shMoveIndex], this.byColor[shMoveIndex], this.byJob[shMoveIndex], this.byGender[shMoveIndex], this.byBind[shMoveIndex], null, this.shLevel[shMoveIndex], this.iPrice[shMoveIndex], this.byDurability[shMoveIndex], this.sGoodsKey[shMoveIndex]);
                this.iIconID[shMoveDestIndex] = this.iIconID[shMoveIndex];
                this.icon[shMoveDestIndex] = this.icon[shMoveIndex];
                this.sGoodsDesc[shMoveDestIndex] = this.sGoodsDesc[shMoveIndex];
                this.bIsGetGoodsDesc[shMoveDestIndex] = this.bIsGetGoodsDesc[shMoveIndex];
            }
            this.deleteGoods(shMoveIndex);
        } else if (num < this.shStackNum[shMoveIndex]) {
            if (this.checkColumnHasGoods(shMoveDestIndex)) {
                this.shStackNum[shMoveDestIndex] = (short) (this.shStackNum[shMoveDestIndex] + num);
            } else {
                this.addGoods(shMoveDestIndex, true, key, this.shGoodsType[shMoveIndex], this.sAlias[shMoveIndex], num, -1, this.byPlace[shMoveIndex], this.byColor[shMoveIndex], this.byJob[shMoveIndex], this.byGender[shMoveIndex], this.byBind[shMoveIndex], null, this.shLevel[shMoveIndex], this.iPrice[shMoveIndex], this.byDurability[shMoveIndex], this.sGoodsKey[shMoveIndex]);
                this.iIconID[shMoveDestIndex] = this.iIconID[shMoveIndex];
                this.icon[shMoveDestIndex] = this.icon[shMoveIndex];
                this.sGoodsDesc[shMoveDestIndex] = this.sGoodsDesc[shMoveIndex];
                this.bIsGetGoodsDesc[shMoveDestIndex] = this.bIsGetGoodsDesc[shMoveIndex];
            }
            this.shStackNum[shMoveIndex] = (short) (this.shStackNum[shMoveIndex] - num);
        }
    }

    //获得物品的颜色值
    public static int getGoodsNameColor(byte byColor) {
        switch (byColor) {
            case 1:
                return 0xffffff;
            case 2:
                return 0x00ff33;
            case 3:
                return 0x33b1fa;
            case 4:
                return 0xff00ff;
            case 5:
                return 0xff9900;
            case 9:
                return 0x999999;
            default:
                return 0xffffff;
        }
    }

    /**
     *  根据物品的品质来绘制物品的名称
     *  1代表白色 ffffff，2代表绿色 00ff33，3代表蓝色 33b1fa，4代表紫色 ff00ff，5代表橙色 ff9900，9代表灰色 999999
     * @param g
     * @param byQuality
     * @param name
     * @param startX
     * @param startY
     */
    public static void drawGoodsName(Graphics g, byte byColor, String name, int startX, int startY) {
        Tools.setColor(g, Goods.getGoodsNameColor(byColor));
        g.drawString(name, startX, startY, 0);
    }

    public void drawGoodsName(Graphics g, short shColumnIndex, int startX, int startY) {
        Tools.setColor(g, Goods.getGoodsNameColor(this.byColor[shColumnIndex]));
        g.drawString(this.sAlias[shColumnIndex], startX, startY, 0);
    }

    /**
     * 简单的物品描述
     * @param name
     * @param shLevel
     * @param byJob
     * @param byGender
     * @return
     */
    public static String makeGoodsSimpleDesc(String name, byte byColor, short shLevel, byte byJob, byte byGender) {
        String temp = "<" + Tools.getColorReplaceLetter(Goods.getGoodsNameColor(byColor)) + name + ">，等级：" + shLevel;
        if (byJob == 0) {
            temp += "，职业要求：无";
        } else if (byJob > 0) {
            temp += "，职业要求:" + Tools.getJobName(byJob);
        }
//        if (byGender == 0) {
//            temp += "，性别要求:男";
//        } else if (byGender == 1) {
//            temp += "，性别要求:女";
//        } else if (byGender == 3) {
//            temp += "，性别要求:无";
//        }
        temp += "。";
        return temp;
    }

    /**
     * 绘S60v5制物品框
     * @param g
     * @param bgPic
     * @param startX
     * @param startY 
     */
    public void drawItemBg(Graphics g, byte byColor, int startX, int startY) {
        //#if NOKIA_S60V5
         g.drawRegion(this.img[5], 0, 0, 17, 17, Constant.TRANS_NONE, startX, startY, 0);
         g.drawRegion(this.img[5], 19, 0, 24, 24, Constant.TRANS_NONE, startX + 17, startY, 0);
         g.drawRegion(this.img[5], 0, 0, 17, 17, Constant.TRANS_ROT180, startX + 24, startY + 24, 0);
         g.drawRegion(this.img[5], 19, 0, 24, 24, Constant.TRANS_ROT180, startX, startY + 17, 0);
         startX += 6;
         startY += 6;
        //#endif
        g.drawImage(this.img[0], startX, startY, 0);
        g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR, startX + 15, startY, 0);
        g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_MIRROR_ROT180, startX, startY + 15, 0);
        g.drawRegion(this.img[0], 0, 0, 15, 15, Constant.TRANS_ROT180, startX + 15, startY + 15, 0);
        if (byColor == -1) {
            return;
        }
        Tools.setColor(g, Goods.getGoodsNameColor(byColor));
        g.drawRect(startX + 1, startY + 1, 27, 27);
        //左上
        g.drawRect(startX + 1, startY + 1, 1, 2);
        g.drawRect(startX + 1, startY + 1, 2, 1);
        //左下
        g.drawRect(startX + 1, startY + 26, 1, 2);
        g.drawRect(startX + 1, startY + 27, 2, 1);
        //右上
        g.drawRect(startX + 26, startY + 1, 2, 1);
        g.drawRect(startX + 27, startY + 1, 1, 2);
        //右下
        g.drawRect(startX + 27, startY + 26, 1, 2);
        g.drawRect(startX + 26, startY + 27, 2, 1);
    }
}
